<?php 
class ControllerProductSpecial extends Controller { 	
	public function index() { 
    	$this->language->load('product/special');
    	$this->data['advanced'] = HTTP_SERVER . 'index.php?route=product/search';
	  	$this->data['template'] = $this->config->get('config_template');  
    	$this->document->title = "Sản Phẩm HOT";
		$this->document->description = "Sản Phẩm HOT";
		$this->document->keywords = "Sản Phẩm HOT";
		$this->data['charset'] = $this->language->get('charset');
		$this->data['lang'] = $this->language->get('code');
		$this->data['direction'] = $this->language->get('direction');
		$this->data['template'] = $this->config->get('config_template');
		$this->data['store'] = $this->config->get('config_name');
		$this->data['link_hinh'] = HTTP_SERVER.'catalog/view/theme/'.$this->config->get('config_template').'/image/';
		if (isset($this->request->get['keyword'])) {
			$this->data['keyword'] = $this->request->get['keyword'];
		} else {
			$this->data['keyword'] = '';
		}
		if (($this->request->server['REQUEST_METHOD'] == 'POST') && isset($this->request->post['language_code'])) {
				$this->session->data['language'] = $this->request->post['language_code'];
			
				if (isset($this->request->post['redirect'])) {
					$this->redirect($this->request->post['redirect']);
				} else {
					$this->redirect(HTTP_SERVER . 'index.php?route=common/home');
				}
	    	}		
			
			if (($this->request->server['REQUEST_METHOD'] == 'POST') && isset($this->request->post['currency_code'])) {
	      		$this->currency->set($this->request->post['currency_code']);
				
				unset($this->session->data['shipping_methods']);
				unset($this->session->data['shipping_method']);
					
				if (isset($this->request->post['redirect'])) {
					$this->redirect($this->request->post['redirect']);
				} else {
					$this->redirect(HTTP_SERVER . 'index.php?route=common/home');
				}
	   		}
			
			$this->language->load('common/header');
			
			if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) {
				$server = HTTPS_IMAGE;
			} else {
				$server = HTTP_IMAGE;
			}
			
			foreach(get_object_vars($this->document) as $key => $value) {
				$this->data[$key] = $value;
			}
			
			if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) {
				$this->data['base'] = HTTPS_SERVER;
			} else {
				$this->data['base'] = HTTP_SERVER;
			}
			
			if ($this->config->get('config_icon') && file_exists(DIR_IMAGE . $this->config->get('config_icon'))) {
				$this->data['icon'] = $server . $this->config->get('config_icon');
			} else {
				$this->data['icon'] = '';
			}
					
			if ($this->config->get('config_logo') && file_exists(DIR_IMAGE . $this->config->get('config_logo'))) {
				$this->data['logo'] = $server . $this->config->get('config_logo');
			} else {
				$this->data['logo'] = '';
			}
		$this->document->breadcrumbs = array();

   		$this->document->breadcrumbs[] = array(
       		'href'      => HTTP_SERVER . 'index.php?route=common/home',
       		'text'      => $this->language->get('text_home'),
      		'separator' => FALSE
   		);
		
		
			
   		$this->document->breadcrumbs[] = array(
       		'href'      => HTTP_SERVER . 'index.php?route=product/special',
       		'text'      => $this->language->get('heading_title'),
      		'separator' => $this->language->get('text_separator')
   		);
		
    	$this->data['heading_title'] = $this->language->get('heading_title');
   
		$this->load->model('catalog/product');
			
		$product_total = $this->model_catalog_product->getProductsHot();
						
		if (count($product_total)) {
				
			$this->load->model('catalog/review');
			$this->load->model('tool/seo_url');
			$this->load->model('tool/image');
			
			$this->data['button_add_to_cart'] = $this->language->get('button_add_to_cart');
			
       		$this->data['products'] = array();
					
			foreach ($product_total as $result) {
				if ($result['image']) {
					$image = $result['image'];
				} else {
					$image = 'no_image.jpg';
				}						
								
				$this->data['products'][] = array(
           			'name'    => $result['name'],
					'model'   => $result['model'],
					'image'	  => HTTPS_IMAGE.$image,
           			'thumb'   => $this->model_tool_image->resize($image, $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height')),
           			'price'   => $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax'))),
					'href'    => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product&product_id=' . $result['product_id'])
       			);
        	}

			
			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/special.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/product/special.tpl';
			} else {
				$this->template = 'default/template/product/special.tpl';
			}
			
			$this->children = array(
				'common/column_right',
				//'common/column_left',
				'common/footer',
				'common/header'
			);
		
			$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));			
		} else {
      		$this->data['text_error'] = $this->language->get('text_empty');

      		$this->data['button_continue'] = $this->language->get('button_continue');

      		$this->data['continue'] = HTTP_SERVER . 'index.php?route=common/home';
	  				
			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
			} else {
				$this->template = 'default/template/error/not_found.tpl';
			}
			
			$this->children = array(
				'common/column_right',
				//'common/column_left',
				'common/footer',
				'common/header'
			);	
			
			$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
		}
  	}
}
?>